forum

home / developersection / forums / how to finds control in gridview

How to finds control in gridview

Anonymous User 2045 06-Oct-2014

I have something weird happening, maybe i don't know of something?

I am trying to populate a Drop Down List (in the editItemTemplate) and also, when the Grid View Loads populate a column, with strings instead of the id's that it contains now.

<asp:TemplateField HeaderText="invsId" SortExpression="invsId">
 <EditItemTemplate>
      <asp:DropDownList ID="ddl_invNames" runat="server" AutoPostBack="True" />
 </EditItemTemplate>
 <ItemTemplate>
      <asp:Label ID="lbl_insLabel" runat="server" Text='<%# Bind("invsId") %>'></asp:Label>
 </ItemTemplate>
 <FooterTemplate>
      <asp:DropDownList ID="ddl_invNamesNew" runat="server" AutoPostBack="True" />
 </FooterTemplate>
</asp:TemplateField>

Cdebehind:

protected void gvAdminArticleAdd_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //111111
                //finding cotrols into the edit rows event              
                if (e.Row.RowState == DataControlRowState.Edit)
                {
                    DropDownList ddlImages = (DropDownList)e.Row.FindControl("ddlImages");
                    ddlImages.DataSource = GetPdfs();
                    ddlImages.DataBind();
 
                    DropDownList ddlinvsNames = (DropDownList)e.Row.FindControl("ddl_invNames");
                    ArrayList invList = GetInvestigatorNames();
                    ddlinvsNames.DataSource = invList;
                    ddlinvsNames.DataBind();
                }
                //222222
                //finding cotrols into rows
                Label insLabel = (Label)e.Row.FindControl("lbl_insLabel");
                int invsLabelId = int.Parse(insLabel.Text);
                insLabel.Text = connection.GetInvsNameById(invsLabelId);
 
            }
        }

The problem that I have occur in the RowDataBound event, I can't figure it up what is wrong

//111111 and //22222 are working correctly(if I comment one of them), but not together. how can it be?

if I place them together I am getting an error on this line of code

int invsLabelId = int.Parse(insLabel.Text);


c# c#  asp.net 
Updated on 06-Oct-2014

I am a content writter !

Can you answer this question?

Answer

1 Answers

Liked By